﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace WPAChess
{
    using System.Windows.Threading;
    public partial class MainPage : PhoneApplicationPage
    {

        private Position position = new Position();


        MiniChessBoardFactory miniBoardFactory = new MiniChessBoardFactory();
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            load();
        }

        private void load()
        {
            this.position.ResetBoard();


            this.Loaded += this.OnRootControlLoaded;
        }



        private void OnRootControlLoaded(object sender, RoutedEventArgs e)
        {
            this.chessBoard.Position = this.position;
        }













        #region Bo dem thoi gian
        
        public class TimerCount
        {
            private int hour = 0;
            private int minute = 0;
            private int second = 0;

            public string TimeSet { get; set; }
            private TextBlock textBlock;

            public TimerCount(TextBlock textBlock)
            {
                this.textBlock = textBlock;

                DispatcherTimer dspTimer = new DispatcherTimer();
                dspTimer.Interval = TimeSpan.FromSeconds(1);

                dspTimer.Tick += OnTimerTick;

                dspTimer.Start();
            }
            public void OnTimerTick(object sender, EventArgs e)
            {
                this.TimeSet = "";
                second += 1;
                hour += (minute == 60) ? 1 : 0;
                minute = (minute == 60) ? 0 : minute;
                minute += (second == 60) ? 1 : 0;
                second = (second == 60) ? 0 : second;

                this.TimeSet += (hour < 10) ? ("0" + hour.ToString()) : hour.ToString();
                this.TimeSet += (minute < 10) ? (":0" + minute.ToString()) : (":" + minute.ToString());
                this.TimeSet += (second < 10) ? (":0" + second.ToString()) : (":" + second.ToString());
                textBlock.Text = this.TimeSet;
            }
        }

        #endregion
    }
}